#!/usr/bin/python
# -*- coding: utf-8 -*-
#===============================================================================
# Copyright 2011 zod.yslin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 
# Author: zod.yslin
# Email: 
# File Name: slice.py
# Description: 
#   s[i:j] = t,  slice of s from i to j is replaced by the contents of the iterable t
#   del s[i:j],  same as s[i:j] = []
#   s[i:j:k] = t,    the elements of s[i:j:k] are replaced by those of t
#   del s[i:j:k],    removes the elements of s[i:j:k] from the list
# Edit History: 
#   2011-08-15    File created.
#===============================================================================
L = range(10)
print(L) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(L[::2]) # [0, 2, 4, 6, 8]
print(L[::-1]) # [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
print(L[1:3]) # [1, 2]
print(L[-1]) # 9
print(L[:-1]) # [0, 1, 2, 3, 4, 5, 6, 7, 8]

a = range(3)
print(a) # [0, 1, 2]
a[1:3] = [4, 5, 6]
print(a) # [0, 4, 5, 6]

a = range(4)
print(a) # [0, 1, 2, 3]
print(a[::2]) # [0, 2]
a[::2] = [0, -1]
print(a) # [0, 1, -1, 3]
#a[::2] = [0,1,2] # ValueError: attempt to assign sequence of size 3 to extended slice of size 2
del a[::2]
print(a) # [1, 3]

print(range(10).__getitem__(slice(0, 5, 2))) # [0, 2, 4]
print(range(10)[slice(0, 5, 2)]) # [0, 2, 4]


